package com.xsky.database;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import junit.framework.TestCase;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.xsky.common.util.UUIDUtil;
import com.xsky.database.dao.impl.BaseEntityDaoImpl;
import com.xsky.operation.vo.TabCompany;

/**
 * Configures and provides access to Hibernate sessions, tied to the current
 * thread of execution. Follows the Thread Local Session pattern, see
 * {@link http://hibernate.org/42.html }.
 */
public class HibernateSessionFactoryTest extends TestCase {
	public void testConnection() {
		TabCompany comp = new TabCompany();
		comp.setId(UUIDUtil.getUUID());
		comp.setAddress("abc");
		comp.setCorpName("好东西");
		comp.setCreatetime(new Date());

		BaseEntityDaoImpl baseDao = new BaseEntityDaoImpl();
		baseDao.saveOrUpdateEntity(comp);
		List list = baseDao.findByKey(comp, "id", comp.getId());
		assertEquals(list.size(), 1);
		TabCompany comp2 =(TabCompany)list.get(0);
		assertEquals(comp2.getId(), comp.getId());
		assertEquals(comp2.getAddress(), comp.getAddress());
		assertEquals(comp2.getCorpName(), comp.getCorpName());
		assertEquals(comp2.getCorpName(), "好东西");
		
		baseDao.delete(comp);
		 list = baseDao.findByKey(comp, "id", comp.getId());
		assertEquals(list.size(), 0);
	}
}

